/*
 * @Copyright: Citylife 2021
 * @Author: WangXinnong
 * @Date: 2021-01-18 23:04:49
 * @Description: SizerUtil
 */
import 'package:flutter/material.dart';

class SizerUtil {
  static double _width;
  static double _height;
  static Orientation _orientation;
  static DeviceType _deviceType;

  static void init(BoxConstraints constraints, Orientation orientation,
      {Size defaultSize = const Size(360, 720)}) {
    //use constraints object for maxWidth and maxHeight of device screen
    _orientation = orientation;
    if (orientation == Orientation.portrait) {
      _width = constraints.maxWidth / defaultSize.width;
      _height = constraints.maxHeight / defaultSize.height;
    } else {
      _width = constraints.maxHeight / defaultSize.width;
      _height = constraints.maxWidth / defaultSize.height;
    }

    //for mobile and tablet screen
    if (_width < 600) {
      _deviceType = DeviceType.Mobile;
    } else {
      _deviceType = DeviceType.Tablet;
    }
  }

  /// height
  static height(var i) {
    return _height * i;
  }

  /// width;
  static width(var i) {
    return _width * i;
  }

  /// font size
  static sp(var i) {
    return _width * i;
  }

  static get orientation => _orientation;

  static get deviceType => _deviceType;
}

enum DeviceType {
  Mobile,
  Tablet,
}
